package com.wlc.base.lambda.compare;

import com.wlc.collection.Hero;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description
 * @date 2021-07-14 09:11
 */
public class TestCompare {

    public static int compareTo(Hero h1, Hero h2) {
        return h1.getHp() > h2.getHp() ? -1 : 1;
    }

    public void method01() {
        List<Hero> list = new ArrayList<>();
        list.add(new Hero("abc", 23));
        list.add(new Hero("abc", 1));
        list.add(new Hero("abc", 43));
        list.add(new Hero("abc", 12));

        /*Collections.sort(list, (h1, h2) -> TestCompare.compareTo(h1, h2));
        list.forEach(System.out::println);
        Collections.shuffle(list);
        System.out.println("=======");
        list.forEach(System.out::println);
        System.out.println("=======");
        Collections.sort(list, (h1, h2) -> h1.getHp() > h2.getHp() ? 1 : -1);
        list.forEach(System.out::println);*/
        list.forEach(System.out::println);
        System.out.println("====");
        Collections.sort(list,TestCompare::compareTo);
        list.forEach(System.out::println);
    }

    public static void main(String[] args) {
        TestCompare testCompare = new TestCompare();
        testCompare.method01();

    }
}
